package br.edu.ufcg.lsd.wbis.ui.client.ui.management;

import br.edu.ufcg.lsd.wbis.ui.client.beans.UserInfo;
import br.edu.ufcg.lsd.wbis.ui.client.services.UserService;
import br.edu.ufcg.lsd.wbis.ui.client.ui.loggedin.util.Refresher;

public class OtherUserInfoManager extends DefaultUserInfoManager {

	private InfoManager<UserInfo> loggedManager;
	
	public OtherUserInfoManager(UserInfo info, InfoManager<UserInfo> loggedManager) {
		super(info);
		this.loggedManager = loggedManager;
	}

	@Override
	protected Refresher<DefaultUserInfoManager> getRefresher() {
		return new Refresher<DefaultUserInfoManager>(this) {

			@Override
			public void run() {
				final UserInfo info = getInfo();
				if (loggedManager != null && info != null && info.getLogin() != null) {
					UserService.Util.getInstance().getUserInfo(loggedManager.getInfo().getLogin(), loggedManager.getInfo().getPassword(), info.getLogin(),
							new UserInfoUpdaterCallback(getRefreshableObject()));
				}
			}

		};
	}
	
	@Override
	public void setInfo(UserInfo info) {
		super.setInfo(info);
	}
}
